package com.centling.smartSealForPhone.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.text.TextUtils;
import android.view.ViewGroup;

import com.centling.smartSealForPhone.constants.UserType;
import com.centling.smartSealForPhone.fragment.DeviceManageFragment;
import com.centling.smartSealForPhone.fragment.PersonCenterFragment;
import com.centling.smartSealForPhone.fragment.SealManageFragment;
import com.centling.smartSealForPhone.fragment.SettingFragment;
import com.centling.smartSealForPhone.fragment.UserManageFragment;

import java.util.ArrayList;

/**
 * @author fionera
 */
public class MainTabAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> fragments;

    public MainTabAdapter(FragmentManager fm, String type, String machineType) {
        super(fm);
        fragments = new ArrayList<>();
        switch (type) {
            case UserType.EQUIP_ADMIN:
                if(!TextUtils.equals(machineType, "0")) {
                    fragments.add(new DeviceManageFragment());
                }
                fragments.add(new PersonCenterFragment());
                fragments.add(new UserManageFragment());
                break;
            case UserType.EQUIP_OPERATOR:
                if(!TextUtils.equals(machineType, "0")) {
                    fragments.add(new DeviceManageFragment());
                }
                fragments.add(new PersonCenterFragment());
                break;
            default:
                fragments.add(new SealManageFragment());
                fragments.add(new PersonCenterFragment());
                break;
        }
        fragments.add(SettingFragment.Companion.getInstance());
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
    }
}
